<?php 
namespace app\admin\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
 * 
 */
class Software extends Model
{
    //软删除
    use SoftDelete;

    //添加场景
    public function add($data)
    {
        # code...
        $validate = new \app\common\validate\Software();
		 if (!$validate->scene('add')->check($data)) {
            return $validate->getError();
        }
        $result=$this->allowField(true)->save($data);
        if ($result) {
			return 1;
		}else{
			return '程序添加失败';
		}


    }
    
    //修改场景
    public function edit($data)
    {
        # code...
        $validate=new \app\common\validate\Software();
        if(!$validate->scene('edit')->check($data)){
                return $validate->getError();
        }
        //查询原来数据

        /***
         *      'name'=>input('post.name'),
         *       'version'=>input('post.version'),
         *       'notice'=>input('post.notice'),
         *      'heart_time'=>input('post.heart_time'),
         *       'software_up'=>input('post.software_up'),
         *       'software_state'=>input('post.software_state'),
         *       'machine_type'=>input('post.machine_type'),
         *       'machine_down'=>input('post.machine_down'),
         *       'machine_recoup'=>input('post.machine_recoup',0)

         */
        
        $softwareInfo=$this->find($data['id']);
        
      

       
        $softwareInfo->softwarename=$data['softwarename'];
       
        $softwareInfo->version=$data['version'];
        $softwareInfo->notice=$data['notice'];
        $softwareInfo->heart_time=$data['heart_time'];
        $softwareInfo->software_up=$data['software_up'];
        $softwareInfo->software_state=$data['software_state'];
        $softwareInfo->machine_type=$data['machine_type'];
        $softwareInfo->machine_down=$data['machine_down'];
        $softwareInfo->machine_recoup=$data['machine_recoup'];
        
        $result=$softwareInfo->save();
        if($result){
            return 1;
        }else{
            return '程序修改失败';
        }


    }


}